//! @file   lc_mutex.h
//! @brief  
//! @author Sayan Chaliha
//! @date   September, 2011
//!
//! 
#ifndef _LC_MUTEX_H
#define _LC_MUTEX_H

#include "libcyan_internal.h"
#include "lc_object.h"
#include "lc_types.h"
#include "lc_system_exception.h"

namespace cyan {
    class CYAN_API Mutex : public Object {
    public:
        Mutex();
        virtual ~Mutex();
        
        void lock();
        Bool tryLock();
        void unlock();
        
    private:
        Mutex(const Mutex&);
        Mutex& operator =(const Mutex&);
        
        MutexType mutex_;
        
        friend class ConditionVariable;
    };
    
    class CYAN_API CriticalSection : public Object {
    public:
        CriticalSection(Mutex& mutex) : mutex_(&mutex) {
            this->mutex_->lock();
        }
        
        virtual ~CriticalSection() {
            this->mutex_->unlock();
        }
        
    private:
        CriticalSection() {
        }
        
        CriticalSection(const CriticalSection&) {
        }
        
        Mutex* mutex_;
    };
}

#endif /* _LC_MUTEX_H */
